#ifndef __DEBUG_PRIMITIVES__DEBUG_PRIMITIVES_H__
#define __DEBUG_PRIMITIVES__DEBUG_PRIMITIVES_H__

#include <public/config.h>
#ifdef CONFIG_OS_ERCOS
#include <public/printf.h>
#else
#include <stdio.h>
#endif


#ifndef CONFIG_DEBUG_PRIMITIVES_SWR_NDEBUG

#define FLDEBUG(fmt,args...)	printf (__FILE__ ":%d: %s: " fmt "\n",		\
												__LINE__, __func__, ##args)
#define DEBUG(fmt,args...)	printf ("%s: " fmt "\n", __func__, ##args)

#define TRACE(expr,type)	DEBUG (#expr " = '%" type "'", expr)
#define ASSERT(expr)		\
	if (! (expr)) {		\
		printf (__FILE__ ":%d: %s: Assertion `" #expr "' failed.\n",	\
										__LINE__, __func__); while(1){}; \
	}
#define PANIC(file, line, str) printf ("%s:%d: %s\n", file, line, 	\
										str ? str : "(null pointer)");\
								printf ("Freezing execution!: while (1);");\
								while (1)
#else

#define DEBUG(fmt,args...)
#define TRACE(expr,type)
#define ASSERT(expr)
#define PANIC(file, line, str)
#endif

#define DEBUG2(fmt,args...)	printf ("%s: " fmt "\n", __func__, ##args)
#define TRACE2(expr,type)	DEBUG (#expr " = '%" type "'", expr)

#define FREEZE()		printf (__FILE__ ":%d: %s: Freezing!", 	\
												__LINE__, __func__); while (1)

#endif // __DEBUG_PRIMITIVES__DEBUG_PRIMITIVES_H__
